Statistics code cleanup, fixed multiple db reload bug.
authorYuri Astrakhan <yurik@users.mediawiki.org>
Thu, 9 Aug 2007 12:27:50 +0000 (12:27 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Thu, 9 Aug 2007 12:27:50 +0000 (12:27 +0000)
includes/SiteStats.php
includes/SpecialStatistics.php

index 65e3eb0..d7b9161 100644 (file)
@@ -5,7 +5,7 @@
  */
 class SiteStats {
        static $row, $loaded = false;
-       static $admins;
+       static $admins, $jobs;
        static $pageCount = array();
 
        static function recache() {
@@ -27,6 +27,8 @@ class SiteStats {
                        $dbr = wfGetDB( DB_SLAVE );
                        self::$row = $dbr->selectRow( 'site_stats', '*', false, __METHOD__ );
                }
+               
+               self::$loaded = true;
        }
        
        static function loadAndLazyInit() {
@@ -104,6 +106,18 @@ class SiteStats {
                return self::$admins;
        }
 
+       static function jobs() {
+               if ( !isset( self::$jobs ) ) {
+                       $dbr = wfGetDB( DB_SLAVE );
+                       self::$jobs = $dbr->estimateRowCount('job');
+                       /* Zero rows still do single row read for row that doesn't exist, but people are annoyed by that */
+                       if (self::$jobs == 1) {
+                               self::$jobs = 0;
+                       }
+               }
+               return self::$jobs;
+       }
+       
        static function pagesInNs( $ns ) {
                wfProfileIn( __METHOD__ );
                if( !isset( self::$pageCount[$ns] ) ) {
index 5fb68f8..6343edd 100644 (file)
@@ -21,13 +21,8 @@ function wfSpecialStatistics() {
        $images = SiteStats::images();
        $total = SiteStats::pages();
        $users = SiteStats::users();
-
-       $admins = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname );
-       $numJobs = $dbr->estimateRowCount('job');
-       /* Zero rows still do single row read for row that doesn't exist, but people are annoyed by that */
-       if ($numJobs == 1) {
-               $numJobs = 0;
-       }
+       $admins = SiteStats::admins();
+       $numJobs = SiteStats::jobs();
 
        if ($action == 'raw') {
                $wgOut->disable();